{extend name="light-year/layout/default" /}

{block name="title"}网站设置{/block}

{block name="content"}
{include file="light-year/layout:plugins/webuploader" /}
{include file="light-year/layout:plugins/editormd" /}
<?php $active_key = input('active_key', 0);?>
<div class="card-header"><h4>基本样式</h4></div>
<div class="card-body">
    <ul id="myTabs" class="nav nav-tabs" role="tablist">
        {if !empty($config_group_list)}
            {foreach $config_group_list as $key => $group_list}
                <li class="{if $active_key == $key}active{/if} margin-bottom-1-rem" onclick="changeUrl(this)">
                    <a active-key="{$key}" href="#config_group_{$key}" data-toggle="tab">{$group_list}</a>
                </li>
            {/foreach}
        {/if}
    </ul>
    <form action="{:url('update')}" method="post" class="edit-form" id="details" return-url="{:url('index')}"
          onsubmit="saveOperation(this);return false;">
        <div id="myTabContent" class="tab-content">
            {if !empty($config_group_list)}
                {foreach $config_group_list as $key => $group_list}
                    <div class="tab-pane fade {if $active_key == $key} active in {/if}" id="config_group_{$key}">
                        {if !empty($configs_list[$key])}
                            {foreach $configs_list[$key] as $config}
                                <div class="form-group">
                                    <label> {$config.config_title} </label>
                                    {switch config.config_type}
                                        {case 3}<!--数组-->
                                            <textarea class="form-control" rows="8" name="{$config.config_name}">{$config.config_value}</textarea>
                                        {/case}
                                        {case 4}<!--枚举-->
                                            <select class="form-control" name="{$config.config_name}">
                                                {if !empty($config.config_extra)}
                                                    {foreach $config.config_extra as $key => $config_extra}
                                                        <option value="{$key}" {if $key == $config.config_value}selected{/if} > {$config_extra} </option>
                                                    {/foreach}
                                                {/if}
                                            </select>
                                        {/case}
                                        {case 5}<!--图片-->
                                            <div>
                                                <input type="hidden" name="{$config.config_name}" value="{$config.config_value}"/>
                                                <div id="{$config.config_name}">
                                                    <div id="{$config.config_name}_filePicker"><i class="icon-cloud-upload"></i></i> 选择单张图片</div>
                                                </div>
                                            </div>
                                            <script>
                                                $(function () {
                                                    $('#{$config.config_name}').append(webUploaderImgHtml('{$config.config_value}', 'input[name={$config.config_name}]', $('#{$config.config_name}_filePicker').attr('span-class')));
                                                })
                                            </script>
                                        {/case}
                                        {case 6}<!--富文本-->
                                            <div id="test-editor-{$config.config_name}" name="{$config.config_name}">
                                                <textarea style="display:none;" name="{$config.config_name}">{:htmlspecialchars_decode($config.config_value)}</textarea>
                                            </div>
                                            <script>
                                                editor_md('test-editor-{$config.config_name}', 300);
                                            </script>
                                        {/case}
                                        {default /}
                                            <input class="form-control" type="text" name="{$config.config_name}" value="{$config.config_value}" placeholder="{$config.config_remarks}" />
                                    {/switch}
                                    {if !empty($config.config_remarks)}
                                        <small class="help-block">
                                            <i class="mdi mdi-information"></i>
                                            {$config.config_remarks}
                                        </small>
                                    {/if}
                                </div>
                            {/foreach}
                        {/if}
                    </div>
                {/foreach}
            {/if}
        </div>
        <hr>
        <div class="form-group">
            <button type="submit" class="btn btn-primary m-r-5">确 定</button>
            <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
    function changeUrl(_this) {
        var stateObject = {id: $(_this).find('a').html()};
        var title = document.title + $(_this).find('a').html();
        var newUrl = thisUrl() + '?active_key=' + $(_this).find('a').attr('active-key');
        // 更改URL地址，但是不做跳转
        history.pushState(stateObject, title, newUrl);
    }
</script>
{/block}